export function query2search(
  query: Record<string, string | number | null | undefined> = {},
  url: string = ''
) {
  const qs: string[] = [];
  for (const key in query) {
    if (Object.prototype.hasOwnProperty.call(query, key)) {
      const value = query[key];
      if (typeof value === 'string' || typeof value === 'number') {
        qs.push(`${key}=${encodeURIComponent(value)}`);
      }
    }
  }

  return qs.length === 0
    ? url
    : url + (url.indexOf('?') !== -1 ? '&' : '?') + qs.join('&');
}

export function string2base(url: string) {
  return Buffer.from(url).toString('base64');
}

export function base2string(url: string) {
  return Buffer.from(url, 'base64').toString();
}
